package net.atomtree.corrsepond.execotor;

import java.text.MessageFormat;
import java.util.Map;

/**
 * Created by czk on 2016/1/2.
 */
public class JobExecutor {
    /**
     *  this executor need you provide a param map,must contain 'host','port'  keys
     *  such as http://101.204.243.107:4040/api/v1/applications/Spark%20Pi/jobs/
     * @param URLParam contain required keys
     * @return one url and you can use this to correspond with spark
     */
    public static String  jobModeExecutor(Map<String,String> URLParam) throws Exception {
        String applicationURL=ApplicationExecutor.appNameModeExecutor(URLParam);
        String jobURL= applicationURL+"jobs/";
        return jobURL;
    }
    /**
     *  this executor need you provide a param map,must contain 'host','port','jobId'  keys
     *  such as http://101.204.243.107:4040/api/v1/applications/Spark%20Pi/jobs/[job-id]
     * @param URLParam contain required keys
     * @return one url and you can use this to correspond with spark
     */
    public static String linkByJobIdModeExecutor(Map<String,String> URLParam) throws Exception {
        String applicationURL=ApplicationExecutor.appNameModeExecutor(URLParam);
        String jobUrlById=MessageFormat.format(applicationURL+"jobs/{0}/",URLParam.get("jobId"));
        return jobUrlById;
    }
}
